package GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;

import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import GUI.Gestion.GUI_Gestion;
import GUI.Gestion.fachada_gestion;
import GUI.almacen.Almacen;
import GUI.ventas.GUI_Ventas;
//import Modelo.BDlocal;

public class Principal extends JFrame {

 
	private static final long serialVersionUID = 1L;

	private JPanel contentPane;
	private Principal yo = this;
	private JPanel panel_4;
	private GUI_Gestion _guiGestion;
	private fachada_gestion _fachadagestion;
	private Ventanalogin login;
	JButton btnInformes; //
	JButton btnGestion;
	JButton btnVentas;
	JButton btnAlmacen;
	private JButton btnSalir;
	//private BDlocal BaseDatos;
	private Connection BD;

	/**
	 * Launch the application.
	 */

	/**
	 * Create the frame.
	 */
	public Principal(Connection con,Ventanalogin v) {
	//	this.BaseDatos = BaseDatos;
        BD=con;
		this.login=v;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(Color.GRAY);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.EAST);
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.GRAY);
		panel.add(panel_1);
		panel_1.setLayout(new BorderLayout(0, 0));

		JPanel panel_2 = new JPanel();
		panel_1.add(panel_2, BorderLayout.SOUTH);

		btnInformes = new JButton("informes");
		btnInformes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		panel_2.setLayout(new GridLayout(0, 1, 0, 0));
		panel_2.add(btnInformes);

		btnGestion = new JButton("Gestion");
		panel_2.add(btnGestion);
		btnGestion.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				_guiGestion = new GUI_Gestion(BD);
				yo.SetInternalPanel(_guiGestion);
			}
		});

		btnVentas = new JButton("Ventas");
		btnVentas.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				GUI_Ventas ventas = new GUI_Ventas(BD);
				yo.SetInternalPanel(ventas);
			}
		});
		panel_2.add(btnVentas);

		btnAlmacen = new JButton("ALMACEN");
		btnAlmacen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				Almacen almacen = new Almacen(BD);
				yo.SetInternalPanel(almacen);
			}
		});
		panel_2.add(btnAlmacen);

		JPanel panel_3 = new JPanel();
		panel_3.setBackground(Color.GRAY);
		panel_3.setSize(new Dimension(200, 10000));
		panel_3.setMinimumSize(new Dimension(200, 200));
		contentPane.add(panel_3, BorderLayout.NORTH);
		panel_3.setLayout(new BorderLayout());
		btnSalir = new JButton("loggout");
		btnSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//	yo.login = new Ventanalogin();
				//	yo.login.setVisible(true);
					
					yo.login.setVisible(true);
					yo.dispose();
			}
		}
		);
		panel_3.add(btnSalir,BorderLayout.EAST);
		/*
		 * GUI_Ventas ventas = new GUI_Ventas(); this.contentPane.add(ventas,
		 * BorderLayout.CENTER);
		 */

		panel_4 = new JPanel();

		javax.swing.ImageIcon Imagen = new javax.swing.ImageIcon(
				"C:/Users/Pol/Documents/eztadiztica/yao_ming_meme_by_lecatinga-d4kpe13.jpg");

		contentPane.add(panel_4, BorderLayout.CENTER);

		JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setIcon(new ImageIcon(
				"C:\\Users\\Pol\\Documents\\eztadiztica\\yao-ming-meme.jpg"));
		panel_4.add(lblNewLabel);
		setExtendedState(MAXIMIZED_BOTH);
		this.setVisible(true);
	}

	public void SetInternalPanel(JPanel panel) {
		this.contentPane.remove(this.panel_4);
		this.panel_4 = panel;
		this.contentPane.add(panel, BorderLayout.CENTER);

		this.setVisible(true);

	}

	public void actualiza() {

		this.setVisible(true);
	}

}
